package mvc.struts.annotation.util;

import java.net.URLDecoder;
import java.net.URLEncoder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CodecUtil {

	private static final Logger LOGGER = LoggerFactory.getLogger(CodecUtil.class);
	
	/**
	 * 
	 * @param source
	 * @return
	 */
	public static String encodeURL(String source)
	{
		String target;
		
		try
		{
			target = URLEncoder.encode(source, "UTF-8");
		}
		catch(Exception ex)
		{
			LOGGER.error("encode url failure", ex);
			throw	new	RuntimeException(ex);
		}
		
		return	target;
	}
	
	/**
	 * 
	 * @param source
	 * @return
	 */
	public static String decodeURL(String source)
	{
		String 	target;
		
		try
		{
			target = URLDecoder.decode(source, "UTF-8");
		}
		catch(Exception ex)
		{
			LOGGER.error("decode url failure", ex);
			throw	new	RuntimeException(ex);
		}
		
		return	target;
	}
}
